const Controller = require('egg').Controller;
class userController extends Controller{
    async registry(){
        let {ctx,service}=this
        let {name,pwd}=ctx.request.body
        if(!name||!pwd){
            ctx.body={
                code:4,
                msg:'缺失参数'
            }
            return
        }
        let res =await service.user.index.getuser(name)
        if(res){
            ctx.body={
                code:3,
                msg:'用户已存在，请重新输入'
            }
            return
        }
        let data=await service.user.index.registry(name,pwd)
        if(data){
            ctx.body={
                code:2,
                msg:'注册成功'
            }
        }else{
            ctx.body={
                code:1,
                msg:'注册失败'
            }
        }
    }
    async login(){
        let {ctx,service}=this
        let {name,pwd}=ctx.request.body
        if(!name||!pwd){
            ctx.body={
                code:4,
                msg:'缺失参数'
            }
            return
        }
        let data = await service.user.index.login(name,pwd)
        if(data){
            ctx.body={
                code:2,
                msg:'登陆成功'
            }
        }else{
            ctx.body={
                code:1,
                msg:'登陆失败'
            }
        }
    }
}
module.exports=userController